<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>

    <!--[if lt IE 9]>
    <script type="text/javascript" src="js/html5shiv.js"></script>
    <script type="text/javascript" src="js/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="js/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>轮播管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 轮播管理 <span
        class="c-gray en">&gt;</span> 图片列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c"> 图片标题：
        <input type="text" name="picTitle" id="picTitle" placeholder=" 图片标题" style="width:250px" class="input-text">
        <input type="checkbox" id="checkbox-1">
        <label for="checkbox-1">在队列</label>
        <button name="searchPic" id="searchPic" class="btn btn-success" type="button"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20"><span><a class="btn btn-primary radius" onclick="picture_add('添加图片','picture-add.html')" href="javascript:void(0);"><i class="Hui-iconfont">&#xe600;</i> 添加图片</a></span>
        <span class="r">共有数据：<strong></strong> 条</span></div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-bg table-hover table-sort">
            <thead>
            <tr class="text-c">
                <th>id</th>
                <th>标题</th>
                <th>链接</th>
                <th>图片</th>
                <th>排序</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="container">

            </tbody>
        </table>
        <div id="page"></div>
    </div>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="js/jquery/jquery-1.8.3.js"></script>
<script type="text/javascript" src="js/layer/2.4/layer.js"></script>
<script type="text/javascript" src="h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="js/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="js/laypage/laypage.js"></script>
<script type="text/javascript">
    var table;
    var showPic = function (pageIndex) {
        var flag = 0;
        if ($("#checkbox-1").is(':checked')) {
            flag = 1;
        }
        $.ajax({
            url: "showImages",
            type: "POST",
            data: {pageIndex: pageIndex || 1, pageSize: 5, title: $("#picTitle").val(), flag: flag},
            dataType: "json",
            success: function (data) {
                $(".r strong").html(data.total);
                $("#container").html("");
                $.each(data.records, function (i, n) {
                    var tr = "<tr class='text-c'>" +
                        "<td>" + n.id + "</td>" +
                        "<td>" + n.title + "</td>" +
                        "<td>" + n.url + "</td>" +
                        "<td><img src='" + n.pic + "' alt='' width='100'/></td>" +
                        "<td>" + n.sortOrder + "</td>";
                    if (n.status === 1) {
                        tr += "<td class='td-status'><span class='label label-success radius'>在队列</span></td>";
                        tr += "<td class='td-manage'>" +
                            "<a style='text-decoration:none' onClick='picture_down(this," + n.id + ")' href='javascript:;' title='移出队列'><i class='Hui-iconfont' style='font-size: 20px'>&#xe6de;</i></a>" +
                            "<a style='text-decoration:none' onClick='picture_edit(" + n.id + ")' href='javascript:;' title='编辑图片'><i class='Hui-iconfont' style='font-size: 20px'>&#xe6df;</i></a></td>";
                    } else {
                        tr += "<td class='td-status'><span class='label label-secondary radius'>未轮播</span></td>";
                        tr += "<td class='td-manage'>" +
                            "<a style='text-decoration:none' onClick='picture_up(this," + n.id + ")' href='javascript:;' title='加入队列'><i class='Hui-iconfont' style='font-size: 20px'>&#xe6dc;</i></a>" +
                            "<a style='text-decoration:none' onClick='picture_edit(" + n.id + ")' href='javascript:;' title='编辑图片'><i class='Hui-iconfont' style='font-size: 20px'>&#xe6df;</i></a></td>";
                    }
                    tr += "</tr>";
                    $("#container").append(tr);
                });
                table = $(".table-bg").dataTable({
                    aaSorting: [[4, "desc"]],
                    paging: false,
                    searching: false,
                    info: false
                });
                laypage({
                    cont: "page",
                    skin: "#00eFFF",
                    pages: data.pages,
                    first: "首页",
                    last: "尾页",
                    curr: pageIndex || 1,
                    jump: function (obj, first) {
                        if (!first) {
                            table.fnClearTable();
                            table.fnDestroy();
                            showPic(obj.curr);
                        }
                    }
                });
            }
        })
    };

    showPic();

    $("#searchPic").click(function () {
        table.fnClearTable();
        table.fnDestroy();
        showPic();
    });

    function picture_add(title, url) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }

    function picture_up(obj, id) {
        layer.confirm("确定要加入轮播队列吗？",function () {
            $.ajax({
                url: "updateStatus",
                type: "POST",
                data: {id: id, status: 1},
                dataType:"json",
                success:function (data) {
                    if(data == true){
                        layer.msg("操作成功",{icon:1,time:500});
                        $(obj).parents("tr").find(".td-manage").prepend("<a style='text-decoration:none' onClick='picture_down(this,"+id+")' href='javascript:;' title='移出队列'><i class='Hui-iconfont' style='font-size: 20px'>&#xe6de;</i></a>");
                        $(obj).parents("tr").find(".td-status").html("<span class='label label-success radius'>在队列</span>");
                        $(obj).remove();
                    }else{
                        layer.msg("操作失败！",{icon:5,time:500});
                    }
                }
            })
        })
    }

    function picture_down(obj, id) {
        layer.confirm("确定要移出轮播队列吗？",function () {
            $.ajax({
                url: "updateStatus",
                type: "POST",
                data: {id: id, status: 0},
                dataType:"json",
                success:function (data) {
                    if(data == true){
                        layer.msg("操作成功",{icon:1,time:500});
                        $(obj).parents("tr").find(".td-manage").prepend("<a style='text-decoration:none' onClick='picture_up(this,"+id+")' href='javascript:;' title='加入队列'><i class='Hui-iconfont' style='font-size: 20px'>&#xe6dc;</i></a>");
                        $(obj).parents("tr").find(".td-status").html("<span class='label label-secondary radius'>未轮播</span>");
                        $(obj).remove();
                    }else{
                        layer.msg("操作失败！",{icon:5,time:500});
                    }
                }
            })
        })
    }

    function picture_edit(id){
        var index = layer.open({
            type: 2,
            title: "图片信息编辑",
            content: "getPic?id=" + id
        });
        layer.full(index);
    }
</script>
</body>
</html>